<?php
namespace Admin\Controller;
use Think\Controller;
class BannerController extends  CommonController{
		
   /**广告列表
    * undocumented function
    *
    * @return void
    * @author 
    **/
   function lists()
   {
  	$data = $this->Model->relation(true)->select();
    $this->assign('data',$data);
   	$this->display();
   }
   /**广告添加
    * undocumented function
    *
    * @return void
    * @author 
    **/
   function add()
   {  

    if(IS_POST){     
      if($_FILES['img']['size']>0){

             $upload = new \Think\Upload();// 实例化上传类    
             $upload->maxSize   =     3145728 ;// 设置附件上传大小   
             $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
             $upload->savePath  =      '/Uploads/'; // 设置附件上传目录    // 上传文件     
             $info   =   $upload->upload();

      if(!$info) {  
            $this->error($upload->getError());    
            }
  $_POST['img'] =__ROOT__.'/Public'.$info['img']['savepath'].$info['img']['savename']; //拼接上传数据库的路径和图片的名称

  $data = $this->Model->data(I('post.'))->add(); 
      if($data>0){
         $this->success('添加成功',(U('banner/lists')),2);die;
      }else{
         $this->error('添加失败',(U('banner/lists')),2);die;
      }
      }   
    }
  $this->display();
   }
   
}